<?php
/**
 * Registry is used as data storage.
 * @package Core
 * @author Urban Soban
 * @copyright 2009 Urban Soban
 */
abstract class Registry {
	/**
	 * Collection of data in Registry
	 * @var array
	 */
	protected $Values = array();
	/**
	 * Registry status
	 * If locked is set to 1, data cannot be written.
	 * @var int
	 */
	protected $Locked = 0;
	
	private function __construct(){}
	
	/**
	 * Retrieves data from Registry
	 *
	 * @param string $key
	 * @return mixed false on failure, data on success
	 */
	function get($key){
		if(isset($this->Values[$key])){
			return $this->Values[$key];
		}
		return false;
	}
	
	/**
	 * Sets data to Registry
	 * If locked, false is returned and data is not set
	 * @param string $key
	 * @param mixed $value
	 * @return bool false on failure, true on success 
	 */
	function set($key, $value){
		if($this->Locked == 0){
			$this->Values[$key] = $value;
			return true;
		}
		
		return false;
	}

	/**
	 * Locks the Registry
	 */
	function lock(){
		$this->Locked = 1;
	}
	
	/**
	 * Unlocks the Registry and makes it writtable
	 */
	function unlock(){
		$this->Locked = 0;
	}
}

class ApplicationRegistry extends Registry {
	private static $Instance;
	
	static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		
		return self::$Instance;
	}
	
}

class SystemRegistry extends Registry {
	private static $Instance;
	
	static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		
		return self::$Instance;
	}
}

class ResultRegistry extends Registry {
	private static $Instance;
	
	static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		
		return self::$Instance;
	}
}

class HTTPRequest {
	private $Values = array();
	
	public function __construct(){
		if(!isset($_GET["q"])){
			return false;	
		}
		
		$RequestURI = $_GET["q"];
		
		$ExplodeQuery = explode("/", $RequestURI);
		
		foreach ($ExplodeQuery as $UrlPart){
			if(!empty($UrlPart)){
				$this->Values[] = $UrlPart;
			}
		}
	}
	
	function get($key){
		if(isset($this->Values[$key])){
			return $this->Values[$key];
		}
		return false;
	}
}

?>